import {
  ModalForm,
  ProFormText,
  ProFormTextArea,
} from "@ant-design/pro-components";
import { Form, message } from "antd";
import React from "react";
import { saveProject, saveSite } from "../../../../api";

const SaveSite = ({ reload,children, payload }:any) => {
  const [form] = Form.useForm();
  return (
    <ModalForm
    width={400}
      trigger={React.cloneElement(children)}
      form={form}
      onOpenChange={(open) => {
        if (open && payload) {
          form.setFieldsValue(payload);
        }
      }}
      onFinish={async (e) => {
        await saveSite(e)
        message.success('保存成功')
        reload()
        return true
      }}
    >
      <ProFormText hidden name="id" label="项目名称" />
      <ProFormText name="name" label="项目名称" />
      <ProFormTextArea name="description" label="项目描述" />
    </ModalForm>
  );
};
export default SaveSite;
